Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
how to make blur all option after select 2 from 4?[jquery]

I want select 3 option from many.After select 3 option,all option will be blur so that anyone can't select more.

Here I added my code,please check it.

Link to File

<!DOCTYPE html>
<html>
<head>
    <title>want to select</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
</head>


<style>
.select {
    border: 1px solid blue;
    height: 25px;
    margin-bottom: 5px;
}
.fill {
    background-color: red;
}
</style>

<body>



<div class="select" id="1">Egg</div>
<div class="select" id="2">mango</div>
<div class="select" id="3">apple</div>
<div class="select" id="4">egg</div>
<div class="select" id="5">apple</div>
<div class="select" id="6">egg</div>




</body>
<script>
$('.select').click(function(e){
    var $et = $(e.target);
    if ($et.hasClass('fill')) { 
        $et.removeClass('fill');
    } else {
        if ($('.fill').length < 3) {
            $et.addClass('fill');
             $et.blur();
        }
    }
});
</script>
</html>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Consider the following.

$(function() {
  $('.select').click(function(e) {
    var $et = $(this);
    if ($et.hasClass('fill')) {
      $et.toggleClass('fill');
    } else if ($et.parent().find(".fill").length < 3) {
      $et.toggleClass('fill');
    }
    return false;
  });
});
.select {
  border: 1px solid blue;
  height: 25px;
  margin-bottom: 5px;
}

.fill {
  background-color: red;
}
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<div class="wrapper">
  <div class="select" id="1">Egg</div>
  <div class="select" id="2">mango</div>
  <div class="select" id="3">apple</div>
  <div class="select" id="4">egg</div>
  <div class="select" id="5">apple</div>
  <div class="select" id="6">egg</div>
</div>

Adding a wrapper allows for better reference to the parent. You can then check how many .fill elements there are inside the wrapper. Now you can conditionally remove or add fill class.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda